<template>
  <div class="loginin">
    <div v-if="state == 1">
      <div>
        <el-input
          placeholder="用户名"
          style="width: 500px"
          v-model="user.username"
        >
          <template slot="prepend"
            ><img
              src="@/assets/img/user.png"
              style="width: 30px; height: 30px"
              alt=""
          /></template>
        </el-input>
      </div>
      <div style="margin-top: 30px">
        <el-input
          placeholder="密码"
          type="password"
          style="width: 500px"
          v-model="user.password"
        >
          <template slot="prepend"
            ><img
              src="@/assets/img/password.png"
              style="width: 30px; height: 30px"
              alt=""
          /></template>
        </el-input>
      </div>
      <div style="margin-top: 30px">
        <el-input
          placeholder="验证码"
          style="width: 400px"
          v-model="vcode"
        >
          <template slot="prepend"
            ><img
              src="@/assets/img/vcode.png"
              style="width: 30px; height: 30px"
              alt=""
          /></template>
        </el-input>
        <img
          id="codeimg"
          @click="changeIma"
          src="http://localhost:81/checkCode/lo"
        />
      </div>
      <div class="loginmid">
        <el-checkbox v-model="checked" style="margin-top:23px"></el-checkbox>
        <h4>记住密码</h4>
      </div>
      <div class="loginbt">
        <el-button type="primary" style="width: 500px" @click="slogin"
          >登录</el-button
        >
      </div>
      <div class="labt">
        <a href="#" @click="phlogin">手机登录</a>
        <a href="#" @click="fopsw">忘记密码</a>
      </div>
    </div>
    <!-- <component :is="startName"></component> -->
  </div>
</template>

<script>
import axios from 'axios'
import Header from '../Header.vue'

export default {
  data() {
    return {
      state: 1,
      user: {
        username: '',
        password: '',
      },
      vcode: '',
      checked: false
    }
  },
  methods: {
    changeIma() {
      var dt = new Date().getMilliseconds() //获取时间毫秒，使参数不同
      document.getElementById('codeimg').src =
        'http://localhost:81/checkCode/lo?' + dt
    },
    //点击登录
    async slogin() {
      const that = this
      const { data: res } = await axios({
        method: 'POST',
        url: 'http://localhost:81/user/login?vcode=' + that.vcode,
        data: that.user,
      })
      console.log('密码登录返回数据', res)
      if (res.code == 200) {
        // this.state = 0
        // //传此数据是为了使登录页消失
        // this.$emit('loginsta',this.state)
        localStorage.setItem('token',res.data)
        that.$router.push('/')
      } else {
        that.$message.error(res.msg)
      }
    },
    //点击手机登录
    phlogin(){
      const that = this
      that.$emit('Registdata','Phonelogin')
    },
    //点击忘记密码
    fopsw(){
      const that = this
      that.$emit('Registdata','Forgitpsw')
    }
  },
  mounted(){
    
  },
  components: {
    Header,
  },
}
</script>

<style lang="less" scoped>
.loginin {
  display: flex;
  position: absolute;
  top: 330px;
  right: 350px;
  width: 500px;
  height: 400px;
}
#codeimg {
  width: 90px;
  height: 35px;
  position: absolute;
  border-radius: 5px;
  margin-left: 5px;
}
.loginmid {
  display: flex;
  position: absolute;
  top: 160px;
  right: 416px;
  input {
    margin-top: 25px;
  }
}
.loginbt {
  display: flex;
  position: absolute;
  top: 220px;
  right: 0;
}
.labt {
  display: flex;
  width: 100%;
  position: absolute;
  top: 260px;
  justify-content: space-between;
}
</style>
